home *** CD-ROM | disk | FTP | other *** search
- /********************************/
- /* File: xwindoid.c */
- /* */
- /* A sample XCMD for Hypercard */
- /* 2.0 that displays and handles*/
- /* an external window. */
- /* */
- /* Well-behaved XCMDs for HC2.0 */
- /* will respond to the ! and ? */
- /* requests by returning version*/
- /* and usage information */
- /* respectively. */
- /* */
- /* ---------------------------- */
- /* ©1990, Donald Koscheka */
- /* All Rights Reserved */
- /********************************/
-
- /*
- Project:
-
- ANSI-A4 -- standard "C" libraries assembled
- off of register A4
-
- MacTraps
- HyperXLib-- Hypercard 2.0 callback library available from
- Apple Computer, Inc.
-
- xwindoid.c (contents of listing 1)
-
- Set Project Type:
- Type == XCMD | XFCN
- Name == xwindoid
- id == -32768..32767
-
- Usage
-
- xwindoid "?"
- xwindoid "!"
- put the result
-
- OR
-
- Put xwindoid( "?" )
- Put xwindoid( "!" )
- */
-
- #include <SetUpA4.h>
- #include <string.h>
- #include <HyperXCMD.h>
-
- #ifndef NIL
- #define NIL (void *)0L
- #endif
-
- #define ETX 0x03
- #define BS 0x08
- #define TAB 0x09
- #define LF 0x0A
- #define NEWLINE 0x0D
- #define CR 0x0D
- #define LEFT_ARROW 0x1C
- #define RIGHT_ARROW 0x1D
- #define UP_ARROW 0x1E
- #define DOWN_ARROW 0x1F
-
- /* Multifinder events and masks */
- #ifndef MouseMovedEvt
- #define MouseMovedEvt 0xFA
- #endif
-
- #ifndef SuspendResumeEvt
- #define SuspendResumeEvt 0x01
- #endif
-
- #ifndef ResumeEvtMask
- #define ResumeEvtMask 0x01
- #endif
-
- #ifndef ConvertScrapMask
- #define ConvertScrapMask 0x02
- #endif
-
-
-
- pascal void HandleHCEvent( XCmdPtr pp );
-
-
- Handle strToParam( str )
- char *str;
- /***************************
- * Given a pointer to a string,
- * copy that string into a handle
- * and return the handle.
- *
- * The input and output strings
- * are both null-terminated
- *
- ***************************/
- {
- Handle outH = NIL;
- long len = 0;
-
- len = strlen( str );
- if( len )
- if( outH = NewHandle( len ) )
- BlockMove( str, *outH, len + 1 );
-
- return( outH );
- }
-
-
- pascal void main( pp )
- XCmdPtr pp;
- {
- Handle answer = NIL;
- char *str;
- long len;
- WindowPtr wind;
- TEHandle hTE;
- Rect bounds;
-
- pp->returnValue = NIL;
-
- if( pp->paramCount < 0 ){
- HandleHCEvent( pp );
- return;
- }
-
- if (pp->paramCount == 1){
- if ( **(pp->params[0]) == '!' ){
- pp->returnValue = strToParam("\pxwindoid XCMD, version 1.0, ©1990, Donald Koscheka");
- return;
- }
-
- if ( **(pp->params[0]) == '?' ){
- pp->returnValue = strToParam("\pSimple xwindoid handler.");
- return;
- }
- }
-
- /* now open a window to play with */
- bounds.top = bounds.left = 0;
- bounds.bottom = 320;
- bounds.right = 500;
- wind = NEWXWINDOW( pp, &bounds, "\pSample Window", FALSE, documentProc, FALSE, FALSE);
- CenterWindow( wind );
-
- }
-
-
-
- pascal void HandleHCEvent( XCmdPtr pp )
- /**********************************
- * Handle events in our xWindows
- * returns true if the event was handled ok
- *
- **********************************/
- {
- XWEventInfoPtr ip = pp->params[0];
- WindowPtr whichWindow;
- short windoPart;
- TEHandle hTE;
- Rect bounds;
- Point hit;
- char theKey;
- GrafPtr oldPort;
- short extend;
-
- pp->passFlag = TRUE; /* seems to be more often the case */
-
- switch( ip->event.what ){
- case mouseDown:
- windoPart = FindWindow( ip->event.where, &whichWindow );
-
- if( whichWindow )
- switch ( windoPart ){
- case inGoAway:
- if (TrackGoAway( whichWindow, ip->event.where) ){
- CLOSEXWINDOW( pp,whichWindow );
- pp->passFlag = FALSE;
- }
- break;
-
- case inDrag:
- /* handled by hypercard */
- break;
-
- case inGrow:
- break;
-
- case inContent:
- if (whichWindow == FrontWindow() ){
- GetPort( &oldPort );
- SetPort( ip->eventWindow );
-
- hTE = (TEHandle)GetWRefCon( ip->eventWindow );
- hit = ip->event.where;
- GlobalToLocal( &hit );
- bounds = (*hTE)->viewRect;
- if( PtInRect( hit, &bounds ) ){
- extend = (short)ip->event.modifiers && shiftKey;
- TEClick( hit, extend, hTE);
- }
- SetPort( oldPort );
- }else
- SelectWindow( whichWindow );
-
- pp->passFlag = FALSE;
- break;
-
- default:
- break;
- }/* window part */
- break;
-
- case mouseUp:
- break;
-
- case keyDown:
- case autoKey:
- /* the command key will be handled by hypercard */
- hTE = (TEHandle)GetWRefCon( ip->eventWindow );
- GetPort( &oldPort );
- SetPort( ip->eventWindow );
- theKey = ip->event.message & 0xFF;
-
- switch( theKey ){
- case TAB:
- break;
-
- case ETX:
- break;
-
- case LEFT_ARROW:
- case RIGHT_ARROW:
- case UP_ARROW:
- case DOWN_ARROW:
- break;
-
- case BS:
- default:
- TEKey( theKey, hTE );
- break;
- }/* switch( theKey ) */
- SetPort( oldPort );
- pp->passFlag = FALSE;
- break;
-
- case activateEvt:
- if ( ip->event.modifiers & activeFlag ){
- BEGINXWEDIT( pp, ip->eventWindow );
- hTE = (TEHandle)GetWRefCon( ip->eventWindow );
- TEActivate( hTE );
- }
- else{
- ENDXWEDIT( pp, ip->eventWindow );
- hTE = (TEHandle)GetWRefCon( ip->eventWindow );
- TEDeactivate( hTE );
- }
- break;
-
- case updateEvt:
- BeginUpdate( ip->eventWindow );
- DrawGrowIcon( ip->eventWindow );
- hTE = (TEHandle)GetWRefCon( ip->eventWindow );
- bounds = (*hTE)->viewRect;
- TEUpdate( &bounds, hTE );
- EndUpdate( ip->eventWindow );
- break;
-
- case app4Evt:
- {
- unsigned char *evtType = &(ip->event.message);
-
- switch( *evtType ){
- case MouseMovedEvt:
- break;
-
- case SuspendResumeEvt:
- break;
- }
- }
- break;
-
-
- /****************************************/
- /* THE HYPERCARD EVENTS */
- /****************************************/
-
-
- case xOpenEvt:
- /* for illustrative purposes, we */
- /* add a text edit field to the */
- /* window */
- SetPort( ip->eventWindow );
- bounds = ip->eventWindow->portRect;
-
- bounds.top += 4;
- bounds.left +=4;
- bounds.bottom -= 16;
- bounds.right -= 16;
- hTE = TENew( &bounds, &bounds );
- (*hTE)->txFont = courier;
- (*hTE)->txFace = 0;
- (*hTE)->txSize = 10;
- SetWRefCon( ip->eventWindow, (long)hTE );
- ShowWindow( ip->eventWindow );
- break;
-
- case xCloseEvt:
- hTE = (TEHandle)GetWRefCon( ip->eventWindow );
- TEDispose( hTE );
- HideWindow( ip->eventWindow );
- break;
-
- case xGiveUpEditEvt:
- hTE = (TEHandle)GetWRefCon( ip->eventWindow );
- TEDeactivate( hTE );
- break;
-
- case xEditUndo:
- break;
-
- case xEditCut:
- break;
-
- case xEditCopy:
- break;
-
- case xEditPaste:
- break;
-
- case xEditClear:
- break;
-
- default:
- GetPort( &oldPort );
- SetPort( ip->eventWindow );
- GetMouse( &hit );
-
- hTE = (TEHandle)GetWRefCon( ip->eventWindow );
- bounds = (*hTE)->viewRect;
- if( PtInRect( hit, &bounds ) ){
- SetCursor( *GetCursor(iBeamCursor) );
- }
- else
- InitCursor();
-
- TEIdle( hTE );
- pp->passFlag = FALSE;
- SetPort( oldPort );
- }/* switch theEvent->what */
- }
-